Skip to content

Fix habit streak counter to require full daily completion of targetGoal#25

Merged
JoeProgrammer88 merged 2 commits intomainfrom
copilot/fix-streak-counter-logic
Mar 1, 2026
Merged

Fix habit streak counter to require full daily completion of targetGoal#25
JoeProgrammer88 merged 2 commits intomainfrom
copilot/fix-streak-counter-logic

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 1, 2026

Streak was incremented on every individual log entry regardless of targetGoal, and had no consecutive-day validation — logging on day 1 and day 3 would produce a streak of 2.

Changes

  • calculateHabitStreak() (new) — derives streak by grouping logs by date, filtering to days where count >= targetGoal, then walking backward through sorted dates counting consecutive days from the most recent fully-completed day
  • logHabitCompletion() — replaces streak + 1 with a call to calculateHabitStreak() on the current log state, so retroactive completions (filling a gap in past days) are correctly reflected
// targetGoal: 3 — partial completion no longer advances streak
logHabitCompletion(habit.id, today); // count=1, streak=0
logHabitCompletion(habit.id, today); // count=2, streak=0
logHabitCompletion(habit.id, today); // count=3, streak=1 ✓

// Retroactive gap-fill
logHabitCompletion(habit.id, day1); // streak=1
logHabitCompletion(habit.id, day3); // streak=1 (gap at day2)
logHabitCompletion(habit.id, day2); // streak=3 ✓
Original prompt

This section details on the original issue you should resolve

<issue_title>Streak counter incorrect</issue_title>
<issue_description>When daily streaks are calculated for habits, it should be the number of days that the entire habit was completed. For example, if a user has Drink Water and it can be repeated 10 times that day, it should only count as a streak if they get all available units completed

If the user goes back to previous days to complete their habits, the streak should continue if they mark all units as completed for that habit</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: JoeProgrammer88 <7156063+JoeProgrammer88@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix incorrect calculation of streak counter for habits Fix habit streak counter to require full daily completion of targetGoal Mar 1, 2026
@JoeProgrammer88 JoeProgrammer88 marked this pull request as ready for review March 1, 2026 22:24
@JoeProgrammer88 JoeProgrammer88 merged commit 0c055d6 into main Mar 1, 2026
1 check passed
@JoeProgrammer88 JoeProgrammer88 deleted the copilot/fix-streak-counter-logic branch March 1, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Streak counter incorrect

2 participants